package com.dbdata.move.service;

import com.dbdata.move.dao.AirLineDao;
import com.dbdata.move.model.AirLine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Richard
 */
@Service
public class AirLineService {
    private static final Logger LOGGER = LoggerFactory.getLogger(AirLineService.class);

    @Autowired
    private AirLineDao dao;

    public Map<String, Long> getAirLineMap() {
        List<AirLine> list = dao.list(AirLine.class);
        Map<String, Long> map = new HashMap<String, Long>(list.size());
        for (AirLine o : list) {
            if (map.containsKey(o.getFullName())) {
                LOGGER.error("已存在相同的航空公司：{}", o.getFullName());
            } else {
                map.put(o.getFullName(), o.getId());
            }
        }
        return map;
    }

    public void isExistAirLine(String airLineName) {
        Map<String, Long> map = getAirLineMap();

        if (!map.containsKey(airLineName.trim())) {
            LOGGER.warn("未找到匹配的航空公司：{}", airLineName);
        }
    }

}
